package cn.maihe.elg.operation.supports.electronicseal.anne.utils.annesign;

import com.google.common.io.Resources;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.util.Base64Utils;

import java.io.IOException;
import java.net.URL;

public class ImageBase64Utils {

    private static final Logger logger = LoggerFactory.getLogger(ImageBase64Utils.class);

    public static String internetImageToBase64(String url) {
        try {
            if (StringUtils.isBlank(url)) {
                return "";
            }
            return Base64Utils.encodeToString(Resources.toByteArray(new URL(url)));
        } catch (IOException e) {
            logger.error("internet image to base64 error:" + url, e);
        }
        return "";
    }



}
